var MenuBar = function(menuId)
{
	$(".dropmenu").click
	(
		function(event)
		{
			hideMenuItems();
			var dropmenuText = $(event.target).text();
			log("Disabled status for " + dropmenuText + " : " + $(event.target).attr("disabled"));
			if ( $(event.target).attr("disabled") === "disabled" )
				return;
			Ui.on_menu_item_click(dropmenuText);
		}
	);
	
    $("div.menubar a").mouseover
    (
		function(event)
		{
			$(".dropmenu ul").each(function(){
				this.style.visibility = "hidden";
			});
		}
    );
    
    $("div.menubar a").click
    (
		function(event)
		{
			$(".dropmenu ul").each(function(){
				this.style.visibility = "hidden";
			});
			
			myLayout.allowOverflow('north');
			var dropmenuName = $(event.target).attr("menu");
			var jqdropmenu = $("#" + dropmenuName + " ul");
			var offset = $(event.target).offset();
			var left = offset.left;
			var top = $(".menubar").offset() + $(".menubar").height();
			top = top + "px";
			left = left + "px";

			var dropmenu = jqdropmenu.get(0);
			dropmenu.style.position = "absolute";
			dropmenu.style.visibility = "visible";
			dropmenu.style.display = "block";
			dropmenu.style.top = top ;
			dropmenu.style.left = left;
		}
    );
    
    $("div.ui-layout-north").mouseover
    (
    	function(event)
    	{
    		myLayout.allowOverflow('north');
    	}
    );
    
    $(".dropmenu ul").mouseout
    (
    	function(event)
    	{
    		myLayout.resetOverflow($(event.target).get(0));
    	}
    ); 
     
    $("div.ui-layout-west").mouseover
    (
    	function(event)
    	{
			$(".dropmenu ul").each(function(){
				this.style.visibility = "hidden";
			});
    	}
    );
    
    $("div.ui-layout-east").mouseover
    (
    	function(event)
    	{
			$(".dropmenu ul").each(function(){
				this.style.visibility = "hidden";
			});
    	}
    );   
    
    $("div.ui-layout-center").mouseover
    (
    	function(event)
    	{
			$(".dropmenu ul").each(function(){
				this.style.visibility = "hidden";
			});
    	}
    );  
    

}

function hideMenuItems()
{
	$(".dropmenu ul").each(function(){
		this.style.visibility = "hidden";
	});
}

var menuBar;

$(
    function()
    {
       menuBar = new MenuBar("#menubar");
    }
);